<!-- build time:Tue Jul 21 2020 12:41:25 GMT+0800 (GMT+08:00) --><!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=2"><meta name="theme-color" content="#222"><meta name="generator" content="Hexo 4.2.0"><link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png"><link rel="icon" type="image/png" sizes="32x32" href="/img/blog_favicon/favicon-32x32-next.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/blog_favicon/favicon-16x16-next.png"><link rel="mask-icon" href="/images/logo.svg" color="#222"><meta name="baidu-site-verification" content="r15J5zOS2KI43yBS"><link rel="stylesheet" href="/css/main.css"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"><link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/themes/blue/pace-theme-minimal.min.css"><script src="//cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/pace.min.js"></script><script id="hexo-configurations">var NexT=window.NexT||{},CONFIG={hostname:new URL("http://www.zhengjiaao.cn").hostname,root:"/",scheme:"Muse",version:"7.6.0",exturl:!1,sidebar:{position:"left",display:"post",padding:18,offset:12,onmobile:!1},copycode:{enable:!0,show_result:!0,style:null},back2top:{enable:!0,sidebar:!1,scrollpercent:!0},bookmark:{enable:!0,color:"#222",save:"auto"},fancybox:!0,mediumzoom:!1,lazyload:!1,pangu:!1,comments:{style:"tabs",active:"valine",storage:!0,lazyload:!1,nav:null,activeClass:"valine"},algolia:{appID:"",apiKey:"",indexName:"",hits:{per_page:10},labels:{input_placeholder:"Search for Posts",hits_empty:"We didn't find any results for the search: ${query}",hits_stats:"${hits} results found in ${time} ms"}},localsearch:{enable:!0,trigger:"auto",top_n_per_article:1,unescape:!1,preload:!1},path:"search.xml",motion:{enable:!0,async:!1,transition:{post_block:"fadeIn",post_header:"slideDownIn",post_body:"slideDownIn",coll_header:"slideLeftIn",sidebar:"slideUpIn"}}}</script><meta property="og:type" content="article"><meta property="og:title" content="Windows-安装-Reids单机和集群-完整版"><meta property="og:url" content="http://www.zhengjiaao.cn/posts/593080288.html"><meta property="og:site_name" content="宇宙小神特别萌"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-b54e338ee43c0b58.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-8b2a76025174ae9c.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-1459082f963bbd6d.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-1c24d7117e6d8f3e.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-167f0d93c35bc0eb.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-7449f8c57d237355.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-20a416ab9636db2e.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-76072fb626b01d97.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-d5ff98b97cfafd53.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-0a3e094315840eca.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-277efc663d0f8bd4.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-61db6bde6a88f27f.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-e704bb28c1d65ee8.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-f1aa6c19e71330b3.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-c98adc8e70b503fd.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-b4f2d1615a25f274.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-f69d7a23ccf028f3.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-4d3a4738c1a67204.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-0cb1c96e22a5486f.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-e623aa52bd3c0bac.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-5ad5601541aa66c3.png"><meta property="article:published_time" content="2020-01-03T08:14:00.000Z"><meta property="article:modified_time" content="2020-07-20T10:37:55.331Z"><meta property="article:author" content="宇宙小神特别萌"><meta property="article:tag" content="Redis"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://upload-images.jianshu.io/upload_images/15645795-b54e338ee43c0b58.png"><link rel="canonical" href="http://www.zhengjiaao.cn/posts/593080288.html"><script id="page-configurations">CONFIG.page={sidebar:"",isHome:!1,isPost:!0}</script><title>Windows-安装-Reids单机和集群-完整版 | 宇宙小神特别萌</title><noscript><style>.sidebar-inner,.use-motion .brand,.use-motion .collection-header,.use-motion .comments,.use-motion .menu-item,.use-motion .pagination,.use-motion .post-block,.use-motion .post-body,.use-motion .post-header{opacity:initial}.use-motion .site-subtitle,.use-motion .site-title{opacity:initial;top:initial}.use-motion .logo-line-before i{left:initial}.use-motion .logo-line-after i{right:initial}</style></noscript><link rel="alternate" href="/atom.xml" title="宇宙小神特别萌" type="application/atom+xml"></head><body itemscope itemtype="http://schema.org/WebPage"><div class="container use-motion"><div class="headband"></div><header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="header-inner"><div class="site-brand-container"><div class="site-meta custom-logo"><div class="site-meta-headline"><a><img class="custom-logo-image" src="/img/blog_favicon/favicon-32x32-next.png" alt="宇宙小神特别萌"></a></div><div><a href="/" class="brand" rel="start"><span class="logo-line-before"><i></i></span> <span class="site-title">宇宙小神特别萌</span> <span class="logo-line-after"><i></i></span></a></div><p class="site-subtitle">ZhengJa</p></div><div class="site-nav-toggle"><div class="toggle" aria-label="切换导航栏"><span class="toggle-line toggle-line-first"></span> <span class="toggle-line toggle-line-middle"></span> <span class="toggle-line toggle-line-last"></span></div></div></div><nav class="site-nav"><ul id="menu" class="menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签<span class="badge">27</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档<span class="badge">116</span></a></li><li class="menu-item menu-item-sitemap"><a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>站点地图</a></li><li class="menu-item menu-item-messageboard"><a href="/messageboard/" rel="section"><i class="fa fa-fw fa-address-book"></i>留言板</a></li><li class="menu-item menu-item-links"><a href="/links/" rel="section"><i class="fa fa-fw fa-user-plus"></i>友链</a></li><li class="menu-item menu-item-shuoshuo"><a href="/shuoshuo/" rel="section"><i class="fa fa-fw fa-file-text-o"></i>说说</a></li><li class="menu-item menu-item-search"><a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索</a></li></ul></nav><div class="site-search"><div class="popup search-popup"><div class="search-header"><span class="search-icon"><i class="fa fa-search"></i></span><div class="search-input-container"><input autocomplete="off" autocorrect="off" autocapitalize="none" placeholder="搜索..." spellcheck="false" type="text" id="search-input"></div><span class="popup-btn-close"><i class="fa fa-times-circle"></i></span></div><div id="search-result"></div></div><div class="search-pop-overlay"></div></div></div></header><div class="back-to-top"><i class="fa fa-arrow-up"></i> <span>0%</span></div><div class="reading-progress-bar"></div><a role="button" class="book-mark-link book-mark-link-fixed"></a> <a href="https://github.com/zhengjiaao" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin:130px 106px" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><main class="main"><div class="main-inner"><div class="content-wrap"><div class="content"><div class="posts-expand"><article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN"><link itemprop="mainEntityOfPage" href="http://www.zhengjiaao.cn/posts/593080288.html"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="image" content="/my-images/avatar.gif"><meta itemprop="name" content="宇宙小神特别萌"><meta itemprop="description" content="人生就是一次幸运的旅行！"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="宇宙小神特别萌"></span><header class="post-header"><h1 class="post-title" itemprop="name headline">Windows-安装-Reids单机和集群-完整版</h1><div class="post-meta"><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-calendar-o"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建时间：2020-01-03 16:14:00" itemprop="dateCreated datePublished" datetime="2020-01-03T16:14:00+08:00">2020-01-03</time> </span><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-calendar-check-o"></i> </span><span class="post-meta-item-text">更新于</span> <time title="修改时间：2020-07-20 18:37:55" itemprop="dateModified" datetime="2020-07-20T18:37:55+08:00">2020-07-20</time> </span><span id="/posts/593080288.html" class="post-meta-item leancloud_visitors" data-flag-title="Windows-安装-Reids单机和集群-完整版" title="热度"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="post-meta-item-text">热度：</span> <span class="leancloud-visitors-count"></span> <span>℃</span> </span><span class="post-meta-item" title="热度" id="busuanzi_container_page_pv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="post-meta-item-text">热度：</span> <span id="busuanzi_value_page_pv"></span> </span><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-comment-o"></i> </span><span class="post-meta-item-text">Valine：</span> <a title="valine" href="/posts/593080288.html#comments" itemprop="discussionUrl"><span class="post-comments-count valine-comment-count" data-xid="/posts/593080288.html" itemprop="commentCount"></span></a></span><br><span class="post-meta-item" title="本文字数"><span class="post-meta-item-icon"><i class="fa fa-file-word-o"></i> </span><span class="post-meta-item-text">本文字数：</span> <span>14k</span> </span><span class="post-meta-item" title="阅读时长"><span class="post-meta-item-icon"><i class="fa fa-clock-o"></i> </span><span class="post-meta-item-text">阅读时长 &asymp;</span> <span>13 分钟</span></span></div></header><div class="post-body" itemprop="articleBody"><meta name="referrer" content="no-referrer"><a id="more"></a><p><img src="https://upload-images.jianshu.io/upload_images/15645795-b54e338ee43c0b58.png" alt="redis目录"></p><h2 id="一、Windows-redis单机安装"><a href="#一、Windows-redis单机安装" class="headerlink" title="一、Windows redis单机安装"></a>一、Windows redis单机安装</h2><h4 id="1、下载Windows-redis版本"><a href="#1、下载Windows-redis版本" class="headerlink" title="1、下载Windows redis版本"></a>1、下载Windows redis版本</h4><p>官方没有 Windows版本的 Redis ，官网介绍：Redis项目不正式支持Windows。但是 ，微软开发并维护了针对Win64的Windows版本。<br>Windows版本下载地址：<a href="https://pan.baidu.com/s/1qopi4Rn3_RpxLP_r6heyNw" target="_blank" rel="noopener">Redis-x64-3.2.100</a> 提取码：jkw2<br>解压：<br><img src="https://upload-images.jianshu.io/upload_images/15645795-8b2a76025174ae9c.png" alt="redis解压.png"></p><p>解压完成后 ，<strong>安装目录</strong>下大概会有以下几个文件：</p><blockquote><ul><li>redis-server.exe：服务端程序 ，提供redis服务</li><li>redis-cli.exe: 客户端程序 ，通过它连接redis服务并进行操作</li><li>redis-check-dump.exe：本地数据库检查</li><li>redis-check-aof.exe：更新日志检查</li><li>redis-benchmark.exe：性能测试 ，用以模拟同时由N个客户端发送M个 SETs/GETs 查询 (类似于 Apache 的ab 工具).</li><li>redis.windows.conf: 配置文件 ，将redis作为普通软件使用的配置 ，命令行关闭则redis关闭</li><li>redis.windows-service.conf：配置文件 ，将redis作为系统服务的配置 ，用以区别开两种不同的使用方式</li></ul><hr></blockquote><p><strong>redis配置文件</strong>含义：redis.windows.conf和redis.windows-service.conf一样 ，两者只是启动方式不同。</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 是否作为守护进程运行</span></span><br><span class="line">daemonize no</span><br><span class="line"><span class="comment"># Redis 默认监听端口</span></span><br><span class="line">port <span class="number">6379</span></span><br><span class="line"><span class="comment"># 客户端闲置多少秒后 ，断开连接</span></span><br><span class="line">timeout <span class="number">300</span></span><br><span class="line"><span class="comment"># 日志显示级别</span></span><br><span class="line">loglevel verbose</span><br><span class="line"><span class="comment"># 指定日志输出的文件名 ，也可指定到标准输出端口</span></span><br><span class="line">logfile redis.log</span><br><span class="line"><span class="comment"># 设置数据库的数量 ，默认最大是16,默认连接的数据库是0 ，可以通过select N 来连接不同的数据库</span></span><br><span class="line">databases <span class="number">32</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># ####### Dump持久化策略 ########</span></span><br><span class="line"><span class="comment"># 当有一条Keys 数据被改变是 ，900 秒刷新到disk 一次</span></span><br><span class="line"><span class="comment"># save 900 1</span></span><br><span class="line"><span class="comment"># 当有10 条Keys 数据被改变时 ，300 秒刷新到disk 一次</span></span><br><span class="line">save <span class="number">300</span> <span class="number">100</span></span><br><span class="line"><span class="comment"># 当有1w 条keys 数据被改变时 ，60 秒刷新到disk 一次</span></span><br><span class="line">save <span class="number">6000</span> <span class="number">10000</span></span><br><span class="line"><span class="comment"># 当dump .rdb 数据库的时候是否压缩数据对象</span></span><br><span class="line">rdbcompression yes</span><br><span class="line"><span class="comment"># dump 持久化数据保存的文件名</span></span><br><span class="line">dbfilename dump.rdb</span><br><span class="line"></span><br><span class="line"><span class="comment">###### ##### Replication</span></span><br><span class="line"><span class="comment"># Redis的主从配置,配置slaveof则实例作为从服务器</span></span><br><span class="line"><span class="comment"># slaveof 192.168.0.105 6379</span></span><br><span class="line"><span class="comment"># 主服务器连接密码</span></span><br><span class="line"><span class="comment"># masterauth &lt;master-password&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">###### ######## 安全性</span></span><br><span class="line"><span class="comment"># 设置连接密码</span></span><br><span class="line"><span class="comment"># requirepass &lt;password&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">###### ######### LIMITS</span></span><br><span class="line"><span class="comment"># 最大客户端连接数</span></span><br><span class="line"><span class="comment"># maxclients 128</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 最大内存使用率</span></span><br><span class="line"><span class="comment"># maxmemory &lt;bytes&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">###### #### APPEND ONLY MODE</span></span><br><span class="line"><span class="comment"># 是否开启日志功能</span></span><br><span class="line">appendonly no</span><br><span class="line"></span><br><span class="line"><span class="comment"># #####AOF持久化策略#####</span></span><br><span class="line"><span class="comment"># appendfsync always</span></span><br><span class="line"><span class="comment"># appendfsync everysec</span></span><br><span class="line"><span class="comment"># appendfsync no</span></span><br><span class="line"><span class="comment">###### ########## VIRTUAL MEMORY</span></span><br><span class="line"><span class="comment"># ###是否开启VM 功能####</span></span><br><span class="line"><span class="comment"># vm-enabled no</span></span><br><span class="line"><span class="comment"># vm-enabled yes</span></span><br><span class="line"><span class="comment"># vm-swap-file logs/redis.swap</span></span><br><span class="line"><span class="comment"># vm-max-memory 0</span></span><br><span class="line"><span class="comment"># vm-page-size 32</span></span><br><span class="line"><span class="comment"># vm-pages 134217728</span></span><br><span class="line"><span class="comment"># vm-max-threads 4</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 使用默认配置文件启动redis会报错的 ，需要修改maxmemory这一项 ，注意单位时字节(209715200是200MB)</span></span><br><span class="line">maxmemory <span class="number">209715200</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 如果需要设置连接密码 ，就修改requirepass ，设为自己的密码。</span></span><br><span class="line">requirepass mypassword</span><br></pre></td></tr></table></figure><p>redis详细配置参考说明地址：<br><a href="https://blog.csdn.net/ljl890705/article/details/51540427" target="_blank" rel="noopener">https://blog.csdn.net/ljl890705/article/details/51540427</a></p><h4 id="2、打开cmd命令进入redis目录-运行redis"><a href="#2、打开cmd命令进入redis目录-运行redis" class="headerlink" title="2、打开cmd命令进入redis目录-运行redis"></a>2、打开cmd命令进入redis目录-运行redis</h4><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="function">D:\<span class="title">Redis</span>-<span class="title">x64</span>-3.2.100&gt;.\<span class="title">redis</span>-<span class="title">server.exe</span> <span class="title">redis.windows.conf</span></span></span><br></pre></td></tr></table></figure><p>启动成功效果: <img src="https://upload-images.jianshu.io/upload_images/15645795-1459082f963bbd6d.png" alt="redis启动成功.png"></p><h4 id="3、查看redis信息"><a href="#3、查看redis信息" class="headerlink" title="3、查看redis信息"></a>3、查看redis信息</h4><p>启动后窗口不要关 ，新开一个cmd窗口 ，执行</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="function">D:\<span class="title">Redis</span>-<span class="title">x64</span>-3.2.100&gt; .\<span class="title">redis</span>-<span class="title">cli</span></span></span><br><span class="line"><span class="function">127.0.0.1:6379&gt;</span></span><br></pre></td></tr></table></figure><p>默认连接本机127.0.0.1 端口号 6379 ，连接成功<br>修改配置文件redis.windows-service.conf</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">将 port <span class="number">6379</span> 端口号 改成 port <span class="number">6380</span></span><br></pre></td></tr></table></figure><h4 id="4、将Redis-加入-Windows-服务-，执行"><a href="#4、将Redis-加入-Windows-服务-，执行" class="headerlink" title="4、将Redis 加入 Windows 服务 ，执行"></a>4、将Redis 加入 Windows 服务 ，执行</h4><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">redis-server --service-install redis.windows.conf --service-name Redis-x64-<span class="number">6380</span> --port <span class="number">6380</span></span><br></pre></td></tr></table></figure><p>提示：Redis successfully installed as a service.<br>表示加入服务成功！<br>如果 Redis 设置了密码 ，加入服务时会提示</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">D:\Redis-x64-3.2.100&gt;redis-server --service-install redis.windows.conf</span><br><span class="line">[7540] 01 Feb 11:02:40.287 # Granting read&#x2F;write access to &#39;NT AUTHORITY\NetworkService&#39; on: &quot;D:\Redis-x64-3.2.100\&quot; &quot;D:\Redis-x64-3.2.100\&quot;</span><br><span class="line">[7540] 01 Feb 11:02:40.288 # Redis successfully installed as a service.</span><br></pre></td></tr></table></figure><p>服务就启动不了 ，可以服务里加参数处理 ，如下图所示： <img src="https://upload-images.jianshu.io/upload_images/15645795-1c24d7117e6d8f3e.png" alt="服务启动加参数密码.png"></p><p>启动参数里加入：<br>123456 是你的Redis密码。<br><strong>单机redis安装完成！</strong></p><h4 id="5、安装redis可视化工具-测试redis"><a href="#5、安装redis可视化工具-测试redis" class="headerlink" title="5、安装redis可视化工具-测试redis"></a>5、安装redis可视化工具-测试redis</h4><p>下载地址:<a href="https://pan.baidu.com/s/1j0Idm9WeythpX2T1kCe8lw" target="_blank" rel="noopener">redis-desktop-manager-0.8.8.384.exe</a> 提取码：ksvp<br>redis-desktop-manager-0.8.8.384.exe 双击安装 ，傻瓜式安装 ，点击下一步就行。安装完成 ，在桌面会生成快捷方式图标 ，<br><img src="https://upload-images.jianshu.io/upload_images/15645795-167f0d93c35bc0eb.png" alt><br><strong>测试连接成功!</strong></p><h2 id="二、Windows搭建Redis-Cluster集群"><a href="#二、Windows搭建Redis-Cluster集群" class="headerlink" title="二、Windows搭建Redis Cluster集群"></a>二、Windows搭建Redis Cluster集群</h2><h4 id="1、下载redis"><a href="#1、下载redis" class="headerlink" title="1、下载redis"></a>1、下载redis</h4><p>Windows版本下载地址：<a href="https://pan.baidu.com/s/1qopi4Rn3_RpxLP_r6heyNw" target="_blank" rel="noopener">Redis-x64-3.2.100</a> 提取码：jkw2<br>解压 ，默认端口6379 <img src="https://upload-images.jianshu.io/upload_images/15645795-7449f8c57d237355.png" alt="redis解压.png"><br>测试是否安装成功:</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">D:\Redis-x64-3.2.100&gt;.\redis-server.exe redis.windows.conf</span><br></pre></td></tr></table></figure><p><img src="https://upload-images.jianshu.io/upload_images/15645795-20a416ab9636db2e.png" alt="redis启动成功.png"></p><h4 id="2、在D盘创建文件夹D-Redis-Cluster"><a href="#2、在D盘创建文件夹D-Redis-Cluster" class="headerlink" title="2、在D盘创建文件夹D:\Redis-Cluster"></a>2、在D盘创建文件夹D:\Redis-Cluster</h4><p>首先我们构建集群节点目录：集群正常运作至少需要三个主节点 ，不过在刚开始试用集群功能时 ， 强烈建议使用六个节点： 其中三个为主节点 ， 而其余三个则是各个主节点的从节点。主节点崩溃 ，从节点的Redis就会提升为主节点 ，代替原来的主节点工作 ，崩溃的主Redis回复工作后 ，会成为从节点.</p><p>拷贝开始下载的redis解压后的目录Redis-x64-3.2.100到D:\Redis-Cluster下 ，并修改文件名 Redis-x64-3.2.100-6381 6382、6383、6384、6385、6386 <img src="https://upload-images.jianshu.io/upload_images/15645795-76072fb626b01d97.png" alt="复制六份redis.png"></p><p>解释一下为什么要复制六份:集群规划有三个节点的集群 ，每个节点有一主一备。需要6台虚拟机.配置 三主三从集群.</p><p>由于 redis 默认端口号为 6379,那么其它5份的端口可以为6381 ，6382 ，6383 ，6384,6385,6386 我们不适用默认的端口号 ，且不与6379冲突 ，保证6379可以。</p><h4 id="3、分别修改这六份的redis配置"><a href="#3、分别修改这六份的redis配置" class="headerlink" title="3、分别修改这六份的redis配置"></a>3、分别修改这六份的redis配置</h4><p>例如 ，打开Redis-x64-3.2.100-6381 下有一个文件 redis.windows.conf 修改里面的端口号 ，以及集群支持配置</p><blockquote><p>port 6381 // 这里把6379改成6381 ，相应的其他5个修改端口号为 6382、6383、6384、6385、6386<br>// 修改其他配置支持集群<br>cluster-enabled yes // 开启集群模式<br>cluster-config-file nodes-6381.conf // 保存节点配置,自动创建,自动更新(建议命名时加上端口号)<br>cluster-node-timeout 15000 // 集群超时时间 ，节点超过这个时间没反应就断定是宕机<br>appendonly yes // 指定是否在每次更新操作后进行日志记录 ，Redis在默认情况下是异步的把数据写入磁盘 ，如果不开启 ，可能会在断电时导致一段时间内的数据丢失。 yes表示：存储方式 ，aof ，将写操作记录保存到日志中</p></blockquote><p>如果cluster-enabled 不为yes ， 那么在使用JedisCluster集群代码获取的时候 ，会报错。<br>cluster-node-timeout 调整为 15000 ，那么在创建集群的时候 ，不会超时。<br>cluster-config-file nodes-6381.conf 是为该节点的配置信息 ，这里使用 nodes-端口.conf命名方法。服务启动后会在目录生成该文件</p><h4 id="4、编写一个-bat-来启动-redis"><a href="#4、编写一个-bat-来启动-redis" class="headerlink" title="4、编写一个 bat 来启动 redis"></a>4、编写一个 bat 来启动 redis</h4><p>在<strong>每个</strong>Redis-x64-3.2.100-*节点目录下建立 start.bat ，内容如下：<br>比如：D:\Redis-Cluster\Redis-x64-3.2.100-6381\start.bat</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">title redis<span class="number">-6381</span></span><br><span class="line">redis-server.exe redis.windows.conf</span><br></pre></td></tr></table></figure><p>将端口分别修改成功6381、6382、6383、6384、6385、6386</p><h4 id="5、系统需要有-Ruby环境"><a href="#5、系统需要有-Ruby环境" class="headerlink" title="5、系统需要有 Ruby环境"></a>5、系统需要有 Ruby环境</h4><p>redis的集群使用 ruby脚本编写 ，所以系统需要有 Ruby 环境 ,下载地址：<br><a href="http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.3.3-x64.exe" target="_blank" rel="noopener">http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.3.3-x64.exe</a><br><img src="https://upload-images.jianshu.io/upload_images/15645795-d5ff98b97cfafd53.png" alt="安装Ruby.png"></p><p><strong>安装时3个选项都勾选。</strong><br>然后对ruby进行配置：<br><img src="https://upload-images.jianshu.io/upload_images/15645795-0a3e094315840eca.png" alt="配置ruby.png"></p><h4 id="6、构建集群脚本redis-trib-rb"><a href="#6、构建集群脚本redis-trib-rb" class="headerlink" title="6、构建集群脚本redis-trib.rb"></a>6、构建集群脚本redis-trib.rb</h4><p>可以打开<a href="https://raw.githubusercontent.com/antirez/redis/unstable/src/redis-trib.rb" target="_blank" rel="noopener">https://raw.githubusercontent.com/antirez/redis/unstable/src/redis-trib.rb</a> 然后复制里面的内容到本地并保存为redis-trib.rb；<br>如下图 ，与redis集群节点保存在同一个文件夹下（比如我所有节点都存放在D:\Redis-Cluster文件夹下）<br><img src="https://upload-images.jianshu.io/upload_images/15645795-277efc663d0f8bd4.png" alt="集群节点目录.png"></p><p>然后依次启动所有集群节点start.bat<br>然后cmd进入redis集群节点D:\Redis-Cluster目录后 ，执行：集群启动命令(–replicas 1 表示为集群中的每个主节点创建一个从节点）</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">D:\Redis-Cluster&gt;.\redis-trib.rb create --replicas 1 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385 127.0.0.1:6386</span><br></pre></td></tr></table></figure><p>如果报错 ，前面加ruby</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">D:\Redis-Cluster&gt;ruby redis-trib.rb create --replicas 1 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385 127.0.0.1:6386</span><br></pre></td></tr></table></figure><p>如果再报-内容如下：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">PS D:\Redis-Cluster&gt; .\redis-trib.rb create --replicas 1 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127</span><br><span class="line">.0.0.1:6385 127.0.0.1:6386</span><br><span class="line">WARNING: redis-trib.rb is not longer available!</span><br><span class="line">You should use redis-cli instead.</span><br><span class="line"></span><br><span class="line">All commands and features belonging to redis-trib.rb have been moved</span><br><span class="line">to redis-cli.</span><br><span class="line">In order to use them you should call redis-cli with the --cluster</span><br><span class="line">option followed by the subcommand name, arguments and options.</span><br><span class="line"></span><br><span class="line">Use the following syntax:</span><br><span class="line">redis-cli --cluster SUBCOMMAND [ARGUMENTS] [OPTIONS]</span><br><span class="line"></span><br><span class="line">Example:</span><br><span class="line">redis-cli --cluster create 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385 127.0.0.1:6386 --cluster-replicas 1</span><br><span class="line"></span><br><span class="line">To get help about all subcommands, type:</span><br><span class="line">redis-cli --cluster help</span><br></pre></td></tr></table></figure><p>redis-trib.rb is not longer available!,可以看出这不是报错 ，是redis-trib.rb版本和你的redis版本不一致 ，这个redis-trib.rb可以从对应版本的redis-XX.tar.gz中的src目录下获取：<br>我的版本是windows的Redis-x64-3.2.100<br>下载地址：<a href="https://github.com/microsoftarchive/redis/releases/tag/win-3.2.100" target="_blank" rel="noopener">https://github.com/microsoftarchive/redis/releases/tag/win-3.2.100</a><br><img src="https://upload-images.jianshu.io/upload_images/15645795-61db6bde6a88f27f.png" alt="下载Source code.png"></p><p>解压-进入redis-win-3.2.100\redis-win-3.2.100\src 找到redis-trib.rb<br><img src="https://upload-images.jianshu.io/upload_images/15645795-e704bb28c1d65ee8.png" alt="3.2.100 redis-trib.rb.png"><br>复制到D:\Redis-Cluster下 <img src="https://upload-images.jianshu.io/upload_images/15645795-f1aa6c19e71330b3.png" alt="集群节点目录.png"></p><h4 id="7、再执行启动集群命令："><a href="#7、再执行启动集群命令：" class="headerlink" title="7、再执行启动集群命令："></a>7、再执行启动集群命令：</h4><p>在D:\Redis-Cluster下 空白处 Shift+右击 选择–在此处打开 PowerShell 窗口(S)</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">D:\Redis-Cluster&gt;ruby redis-trib.rb create --replicas 1 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385 127.0.0.1:6386</span><br></pre></td></tr></table></figure><p><img src="https://upload-images.jianshu.io/upload_images/15645795-c98adc8e70b503fd.png" alt="成功启动集群命令成功效果.png">上图可看出 主节点为6381,6382,6383端口的三个地址 ，6384,6385,6386为三个从节点：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Adding replica 127.0.0.1:6384 to 127.0.0.1:6381</span><br><span class="line">Adding replica 127.0.0.1:6385 to 127.0.0.1:6382</span><br><span class="line">Adding replica 127.0.0.1:6386 to 127.0.0.1:6383</span><br></pre></td></tr></table></figure><p>中途会询问是否打印更多详细信息 ，输入yes即可 ，然后redis-trib 就会将这份配置应用到集群当中,让各个节点开始互相通讯：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">Can I set the above configuration? (type &#39;yes&#39; to accept): yes</span><br><span class="line">&gt;&gt;&gt; Nodes configuration updated</span><br><span class="line">&gt;&gt;&gt; Assign a different config epoch to each node</span><br><span class="line">&gt;&gt;&gt; Sending CLUSTER MEET messages to join the cluster</span><br><span class="line">Waiting for the cluster to join.....</span><br><span class="line">&gt;&gt;&gt; Performing Cluster Check (using node 127.0.0.1:6381)</span><br><span class="line">M: b7881780481d4ebffff5a2e140cb0b9778dd3b86 127.0.0.1:6381</span><br><span class="line">   slots:0-5460 (5461 slots) master</span><br><span class="line">M: 8cf2636d55e5f54a31fea21dbf12adf3515e5aef 127.0.0.1:6382</span><br><span class="line">   slots:5461-10922 (5462 slots) master</span><br><span class="line">M: 4b312b45a43484ac6f9a1a9a63f34345ec0c163f 127.0.0.1:6383</span><br><span class="line">   slots:10923-16383 (5461 slots) master</span><br><span class="line">M: 98ab54d6f8dac11a8911762be3cdc2f211562bcd 127.0.0.1:6384</span><br><span class="line">   slots: (0 slots) master</span><br><span class="line">   replicates b7881780481d4ebffff5a2e140cb0b9778dd3b86</span><br><span class="line">M: 20697b746d07108220e7476a172fdb1b8e429069 127.0.0.1:6385</span><br><span class="line">   slots: (0 slots) master</span><br><span class="line">   replicates 8cf2636d55e5f54a31fea21dbf12adf3515e5aef</span><br><span class="line">M: 081a9f17a774ab5e279ef6d193a5a2cc4393c91b 127.0.0.1:6386</span><br><span class="line">   slots: (0 slots) master</span><br><span class="line">   replicates 4b312b45a43484ac6f9a1a9a63f34345ec0c163f</span><br><span class="line">[OK] All nodes agree about slots configuration.</span><br><span class="line">&gt;&gt;&gt; Check for open slots...</span><br><span class="line">&gt;&gt;&gt; Check slots coverage...</span><br><span class="line">[OK] All 16384 slots covered.</span><br></pre></td></tr></table></figure><p>Redis集群数据分配策略：<br>采用一种叫做哈希槽 (hash slot)的方式来分配数据 ，redis cluster 默认分配了 16384 个slot ，三个节点分别承担的slot 区间是：（如上面3个M:节点的slots描述）</p><blockquote><p>节点6380覆盖0－5460;<br>节点6381覆盖5461－10922;<br>节点6382覆盖10923－16383.</p></blockquote><p>最后查看所有集群节点 ，会看到：<br><img src="https://upload-images.jianshu.io/upload_images/15645795-b4f2d1615a25f274.png" alt><br><strong>测试集群搭建成功！</strong></p><h4 id="8、测试集群"><a href="#8、测试集群" class="headerlink" title="8、测试集群"></a>8、测试集群</h4><p>进入任意一个集群节点 ，cmd执行 redis-cli.exe -c -p 6381<br>写入任意一个value ，查询 <img src="https://upload-images.jianshu.io/upload_images/15645795-f69d7a23ccf028f3.png" alt>再写一个hash测试: hset redis:test:hash Hash1 12345</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">PS D:\Redis-Cluster\Redis-x64-3.2.100-6381&gt; .\redis-cli.exe  -c -p 6381</span><br><span class="line">127.0.0.1:6381&gt; set name redis-test</span><br><span class="line">-&gt; Redirected to slot [5798] located at 127.0.0.1:6382</span><br><span class="line">OK</span><br><span class="line">127.0.0.1:6382&gt; get name</span><br><span class="line">&quot;redis-test&quot;</span><br><span class="line">127.0.0.1:6382&gt; set name redis-test2</span><br><span class="line">OK</span><br><span class="line">127.0.0.1:6382&gt; get name</span><br><span class="line">&quot;redis-test2&quot;</span><br><span class="line">127.0.0.1:6382&gt; hset redis:hash Hash1 123456</span><br><span class="line">-&gt; Redirected to slot [5427] located at 127.0.0.1:6381</span><br><span class="line">(integer) 1</span><br><span class="line">127.0.0.1:6381&gt;</span><br></pre></td></tr></table></figure><p>可以看到集群会用CRC16算法来取模得到所属的slot ，然后将这个key分到哈希槽区间的节点上CRC16(key) % 16384</p><p>所以 ，可以看到我们set的key计算之后被分配到了slot-5427 上 ， 而slot-5427处在节点6381上 ，因此redis自动redirect到了6381节点上.</p><h4 id="9、附上所有工具及搭建的redis集群下载地址："><a href="#9、附上所有工具及搭建的redis集群下载地址：" class="headerlink" title="9、附上所有工具及搭建的redis集群下载地址："></a>9、附上所有工具及搭建的redis集群下载地址：</h4><p><a href="https://pan.baidu.com/s/1I9Ix6C2kQ4ydAKiDQKg5eA" target="_blank" rel="noopener">下载集群测试</a> 提取码：ef4a<br>随便放到一个磁盘里 ，安装Ruby之后 ，就可以启动集群命令-测试集群！</p><p>##三、springboot redis单机和集群配置<br>####1、springboot redis单机代码实例<br><a href="https://www.jianshu.com/p/5596c3a4978d" target="_blank" rel="noopener">springboot+redis项目实战完整篇</a></p><p>####2、springboot redis集群代码实例<br>#####1、配置集群<br>在 <a href="https://www.jianshu.com/p/5596c3a4978d" target="_blank" rel="noopener">springboot+redis项目实战完整篇</a> 的基础上 ，修改yml中的redis配置:</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">redis:</span></span><br><span class="line">    <span class="comment">#host: localhost  # redis单机配置</span></span><br><span class="line">    <span class="comment">#port: 6379</span></span><br><span class="line">    <span class="attr">max-wait:</span> <span class="number">30000</span>    <span class="comment"># 连接池最大阻塞等待时间（使用负值表示没有限制）</span></span><br><span class="line">    <span class="attr">max-active:</span> <span class="number">100</span>   <span class="comment"># 连接池最大连接数（使用负值表示没有限制）</span></span><br><span class="line">    <span class="attr">max-idle:</span> <span class="number">20</span>     <span class="comment"># 连接池中的最大空闲连接</span></span><br><span class="line">    <span class="attr">min-idle:</span> <span class="number">0</span>     <span class="comment"># 连接池中的最小空闲连接</span></span><br><span class="line">    <span class="attr">timeout:</span> <span class="number">5000</span>   <span class="comment"># 连接超时</span></span><br><span class="line">    <span class="comment">#password: 123456 # 密码</span></span><br><span class="line">    <span class="attr">cluster:</span>       <span class="comment">#  redis集群配置</span></span><br><span class="line">      <span class="attr">nodes:</span> <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span><span class="string">:6381,127.0.0.1:6382,127.0.0.1:6383,127.0.0.1:6384,127.0.0.1:6385,127.0.0.1:6386</span></span><br><span class="line">      <span class="attr">max-redirects:</span> <span class="number">2</span>  <span class="comment"># 最大重定向次数</span></span><br></pre></td></tr></table></figure><p>#####2、测试集群配置<br>可以不用Postman测试接口 ，也可以用下面的方式测试：用swagger方式测试接口很方便。<br>pom.xml</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--集成swagger-API--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.swagger<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>swagger-models<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">scope</span>&gt;</span>compile<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.swagger<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>swagger-annotations<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">scope</span>&gt;</span>compile<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.springfox<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>springfox-swagger-ui<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.springfox<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>springfox-swagger2<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">exclusions</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">exclusion</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.swagger<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>swagger-models<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;/<span class="name">exclusion</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">exclusion</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.swagger<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>swagger-annotations<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;/<span class="name">exclusion</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">exclusions</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure><p>config文件夹下添加swagger配置类：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.dist.config;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.google.common.base.Predicate;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Bean;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Configuration;</span><br><span class="line"><span class="keyword">import</span> springfox.documentation.builders.ApiInfoBuilder;</span><br><span class="line"><span class="keyword">import</span> springfox.documentation.builders.PathSelectors;</span><br><span class="line"><span class="keyword">import</span> springfox.documentation.service.ApiInfo;</span><br><span class="line"><span class="keyword">import</span> springfox.documentation.service.Contact;</span><br><span class="line"><span class="keyword">import</span> springfox.documentation.spi.DocumentationType;</span><br><span class="line"><span class="keyword">import</span> springfox.documentation.spring.web.plugins.Docket;</span><br><span class="line"><span class="keyword">import</span> springfox.documentation.swagger2.annotations.EnableSwagger2;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> yangmin</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span> 2018/8/15</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@desc</span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="meta">@EnableSwagger</span>2</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Swaggwe2Config</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Docket <span class="title">adminApi</span><span class="params">()</span></span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> Docket(DocumentationType.SWAGGER_2)</span><br><span class="line">                .groupName(<span class="string">"Admin API"</span>)</span><br><span class="line">                .forCodeGeneration(<span class="keyword">true</span>)</span><br><span class="line">                .pathMapping(<span class="string">"/"</span>)</span><br><span class="line">                .select()</span><br><span class="line">                .paths(paths())</span><br><span class="line">                .build()</span><br><span class="line">                .apiInfo(apiInfo())</span><br><span class="line">                .useDefaultResponseMessages(<span class="keyword">false</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> Predicate&lt;String&gt; <span class="title">paths</span><span class="params">()</span></span>&#123;</span><br><span class="line">        <span class="keyword">return</span> PathSelectors.regex(<span class="string">"^/(?!error).*$"</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> ApiInfo <span class="title">apiInfo</span><span class="params">()</span></span>&#123;</span><br><span class="line">        Contact contact = <span class="keyword">new</span> Contact(<span class="string">"BaiDu"</span>, <span class="string">"controller://baidu.com"</span>, <span class="string">" zhengja@dist.com.cn"</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> ApiInfoBuilder()</span><br><span class="line">                .title(<span class="string">"个人SpringBoot测试系统"</span>)</span><br><span class="line">                .description(<span class="string">"开发API文档"</span>)</span><br><span class="line">                .contact(contact)</span><br><span class="line">                .version(<span class="string">"1.0"</span>)</span><br><span class="line">                .build();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>Controller测试接口</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.dist.controller;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.dist.utils.RedisUtil;</span><br><span class="line"><span class="keyword">import</span> io.swagger.annotations.Api;</span><br><span class="line"><span class="keyword">import</span> io.swagger.annotations.ApiOperation;</span><br><span class="line"><span class="keyword">import</span> io.swagger.annotations.ApiParam;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.RequestMapping;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.RequestMethod;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.RequestParam;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.RestController;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.annotation.Resource;</span><br><span class="line"><span class="keyword">import</span> java.util.HashMap;</span><br><span class="line"><span class="keyword">import</span> java.util.Iterator;</span><br><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"><span class="keyword">import</span> java.util.Set;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> zhengja@dist.com.cn</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@data</span> 2019/6/17 17:28</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@RequestMapping</span>(value = <span class="string">"rest/redis"</span>)</span><br><span class="line"><span class="meta">@Api</span>(tags = &#123;<span class="string">"RedisUtilController"</span>&#125;, description = <span class="string">"redisUtil测试"</span>)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RedisUtil2Controller</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Resource</span></span><br><span class="line">    <span class="keyword">private</span> RedisUtil redisUtil;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@RequestMapping</span>(value = <span class="string">"v1/redisSave"</span>,method = &#123;RequestMethod.GET&#125;)</span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"保存到redis,并返回结果"</span>,notes = <span class="string">"保存到redis"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">redisSave</span><span class="params">(@ApiParam(value = <span class="string">"传入key值"</span>)</span> @RequestParam String key,</span></span><br><span class="line"><span class="function">                        @<span class="title">ApiParam</span><span class="params">(value = <span class="string">"传入value值"</span>)</span> @RequestParam String value)</span>&#123;</span><br><span class="line">        redisUtil.set(key,value);</span><br><span class="line">        <span class="keyword">return</span> redisUtil.get(key);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@RequestMapping</span>(value = <span class="string">"v1/redisGetAllKeyValue"</span>,method = &#123;RequestMethod.GET&#125;)</span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"获取redis种所有key和value值"</span>,notes = <span class="string">"获取redis种所有key和value值"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">redisGetAllKeyValue</span><span class="params">()</span></span>&#123;</span><br><span class="line">        Set&lt;String&gt; keys = redisUtil.keys(<span class="string">"*"</span>);</span><br><span class="line">        Iterator&lt;String&gt; iterator = keys.iterator();</span><br><span class="line">        Map&lt;String,Object&gt; map = <span class="keyword">new</span> HashMap&lt;&gt;();</span><br><span class="line">        <span class="keyword">while</span> (iterator.hasNext())&#123;</span><br><span class="line">            String key = iterator.next();</span><br><span class="line">            Object o = redisUtil.get(key);</span><br><span class="line">            map.put(key,o);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> map;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="meta">@RequestMapping</span>(value = <span class="string">"v1/deleteRedisAll"</span>,method = &#123;RequestMethod.DELETE&#125;)</span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"清除redis所有缓存"</span>,notes = <span class="string">"清除redis所有缓存"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">deleteRedisAll</span><span class="params">()</span></span>&#123;</span><br><span class="line">        Set&lt;String&gt; keys = redisUtil.keys(<span class="string">"*"</span>);</span><br><span class="line">        Iterator&lt;String&gt; iterator = keys.iterator();</span><br><span class="line">        <span class="keyword">while</span> (iterator.hasNext())&#123;</span><br><span class="line">            redisUtil.del(iterator.next());</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">"删除redis所有数据成功"</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@RequestMapping</span>(value = <span class="string">"v1/getRedisValue"</span>,method = &#123;RequestMethod.GET&#125;)</span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"根据key获取value值"</span>,notes = <span class="string">"根据key获取value值"</span>)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">getRedisValue</span><span class="params">(@ApiParam(value = <span class="string">"传入key值"</span>)</span> @RequestParam String key)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> redisUtil.get(key);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>在resources/static下创建index.html</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">"en"</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"UTF-8"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">title</span>&gt;</span>springboot-test-redis<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">h1</span>&gt;</span>首页面<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">h2</span>&gt;</span>springboot-test-redis<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">" http://localhost:8080/springboot-test-redis/swagger-ui.html"</span>&gt;</span>进入swagger页面测试<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure><p><strong>上面的 <a href="http://localhost:8080/springboot-test-redis修改成自己的项目访问路径" target="_blank" rel="noopener">http://localhost:8080/springboot-test-redis修改成自己的项目访问路径</a></strong></p><p>######3、测试效果<br>redis保存数据: <img src="https://upload-images.jianshu.io/upload_images/15645795-4d3a4738c1a67204.png" alt="redis保存数据-效果.png"><br>redis根据key查询value数据：<br><img src="https://upload-images.jianshu.io/upload_images/15645795-0cb1c96e22a5486f.png" alt="redis查询数据-效果.png"><br><img src="https://upload-images.jianshu.io/upload_images/15645795-e623aa52bd3c0bac.png" alt="redis查询数据-效果2.png"><br>redis查询所有数据：<br><img src="https://upload-images.jianshu.io/upload_images/15645795-5ad5601541aa66c3.png" alt="redis查询所有数据-效果.png"></p></div><div class="popular-posts-header"><p style="font-size:18px;color:red;margin:0 0 5px 0">相关文章推荐：</p></div><ul class="popular-posts"><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\1333463013.html" rel="bookmark">springBoot配置Redis多数据源+完整测试</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\703432472.html" rel="bookmark">redis安装及基本语法</a></div></li></ul><div><div style="text-align:center;color:#ccc;font-size:14px">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div></div><div class="reward-container"><div><p style="font-size:14px;color:#34495e;margin:0 0 5px 0">赞赏一下吧～ 还可以关注公众号订阅最新内容</p></div><button disable="enable" onclick="var qr = document.getElementById(&quot;qr&quot;); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">打赏</button><div id="qr" style="display:none"><div style="display:inline-block"><img src="/my-images/WeChat.png" alt="宇宙小神特别萌 微信支付"><p>微信支付</p></div><div style="display:inline-block"><img src="/my-images/Alipay.png" alt="宇宙小神特别萌 支付宝"><p>支付宝</p></div></div></div><footer class="post-footer"><div class="post-tags"><a href="/tags/Redis/" rel="tag"><i class="fa fa-tag"></i> Redis</a></div><div class="post-nav"><div class="post-nav-item"><a href="/posts/126491095.html" rel="prev" title="aa"><i class="fa fa-chevron-left"></i> aa</a></div><div class="post-nav-item"><a href="/posts/4128767596.html" rel="next" title="jenkins-FTP配置">jenkins-FTP配置 <i class="fa fa-chevron-right"></i></a></div></div></footer></article></div></div><div class="comments" id="valine-comments"></div><script>window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }</script></div><div class="toggle sidebar-toggle"><span class="toggle-line toggle-line-first"></span> <span class="toggle-line toggle-line-middle"></span> <span class="toggle-line toggle-line-last"></span></div><aside class="sidebar"><div class="sidebar-inner"><ul class="sidebar-nav motion-element"><li class="sidebar-nav-toc">文章目录</li><li class="sidebar-nav-overview">站点概览</li></ul><div class="post-toc-wrap sidebar-panel"><div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、Windows-redis单机安装"><span class="nav-text">一、Windows redis单机安装</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1、下载Windows-redis版本"><span class="nav-text">1、下载Windows redis版本</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2、打开cmd命令进入redis目录-运行redis"><span class="nav-text">2、打开cmd命令进入redis目录-运行redis</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3、查看redis信息"><span class="nav-text">3、查看redis信息</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4、将Redis-加入-Windows-服务-，执行"><span class="nav-text">4、将Redis 加入 Windows 服务 ，执行</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5、安装redis可视化工具-测试redis"><span class="nav-text">5、安装redis可视化工具-测试redis</span></a></li></ol></li></ol><li class="nav-item nav-level-2"><a class="nav-link" href="#二、Windows搭建Redis-Cluster集群"><span class="nav-text">二、Windows搭建Redis Cluster集群</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1、下载redis"><span class="nav-text">1、下载redis</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2、在D盘创建文件夹D-Redis-Cluster"><span class="nav-text">2、在D盘创建文件夹D:\Redis-Cluster</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3、分别修改这六份的redis配置"><span class="nav-text">3、分别修改这六份的redis配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4、编写一个-bat-来启动-redis"><span class="nav-text">4、编写一个 bat 来启动 redis</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5、系统需要有-Ruby环境"><span class="nav-text">5、系统需要有 Ruby环境</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#6、构建集群脚本redis-trib-rb"><span class="nav-text">6、构建集群脚本redis-trib.rb</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7、再执行启动集群命令："><span class="nav-text">7、再执行启动集群命令：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#8、测试集群"><span class="nav-text">8、测试集群</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#9、附上所有工具及搭建的redis集群下载地址："><span class="nav-text">9、附上所有工具及搭建的redis集群下载地址：</span></a></li></ol></li></div></div><div class="site-overview-wrap sidebar-panel"><div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person"><img class="site-author-image" itemprop="image" alt="宇宙小神特别萌" src="/my-images/avatar.gif"><p class="site-author-name" itemprop="name">宇宙小神特别萌</p><div class="site-description" itemprop="description">人生就是一次幸运的旅行！</div></div><div class="site-state-wrap motion-element"><nav class="site-state"><div class="site-state-item site-state-posts"><a href="/archives/"><span class="site-state-item-count">116</span> <span class="site-state-item-name">文章</span></a></div><div class="site-state-item site-state-tags"><a href="/tags/"><span class="site-state-item-count">27</span> <span class="site-state-item-name">标签</span></a></div></nav></div><div class="links-of-author motion-element"><span class="links-of-author-item"><a href="https://github.com/zhengjiaao" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;zhengjiaao" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a> </span><span class="links-of-author-item"><a href="https://www.jianshu.com/u/70d69269bd09" title="简书 → https:&#x2F;&#x2F;www.jianshu.com&#x2F;u&#x2F;70d69269bd09" rel="noopener" target="_blank"><i class="fa fa-fw fa-book"></i>简书</a> </span><span class="links-of-author-item"><a href="/atom.xml" title="RSS → &#x2F;atom.xml"><i class="fa fa-fw fa-rss"></i>RSS</a></span></div><div class="links-of-blogroll motion-element"><div class="links-of-blogroll-title"><i class="fa fa-fw fa-link"></i> 推荐阅读</div><ul class="links-of-blogroll-list"><li class="links-of-blogroll-item"><a href="https://github.com/spring-projects" title="https:&#x2F;&#x2F;github.com&#x2F;spring-projects" rel="noopener" target="_blank">spring-projects</a></li><li class="links-of-blogroll-item"><a href="http://www.alloyteam.com/nav/" title="http:&#x2F;&#x2F;www.alloyteam.com&#x2F;nav&#x2F;" rel="noopener" target="_blank">Web前端导航</a></li><li class="links-of-blogroll-item"><a href="http://www.chuangzaoshi.com/code" title="http:&#x2F;&#x2F;www.chuangzaoshi.com&#x2F;code" rel="noopener" target="_blank">创造狮导航</a></li></ul></div></div></div></aside><div id="sidebar-dimmer"></div></div></main><footer class="footer"><div class="footer-inner"><div class="copyright">&copy; <span itemprop="copyrightYear">2020</span> <span class="with-love"><i class="fa fa-heart"></i> </span><span class="author" itemprop="copyrightHolder">宇宙小神特别萌</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-area-chart"></i> </span><span title="站点总字数">1.2m</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-coffee"></i> </span><span title="站点阅读时长">17:41</span></div><div class="busuanzi-count"><script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span class="post-meta-item" id="busuanzi_container_site_uv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-user"></i> </span><span class="site-uv" title="总访客量"><span id="busuanzi_value_site_uv"></span> </span></span><span class="post-meta-divider">|</span> <span class="post-meta-item" id="busuanzi_container_site_pv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="site-pv" title="总访问量"><span id="busuanzi_value_site_pv"></span></span></span></div></div></footer></div><script src="//cdn.jsdelivr.net/npm/animejs@3.1.0/lib/anime.min.js"></script><script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script><script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/velocity/1.2.1/velocity.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/velocity/1.2.1/velocity.ui.min.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script><script src="/js/bookmark.js"></script><script>!function(){var t=document.createElement("script"),e=window.location.protocol.split(":")[0];t.src="https"===e?"https://zz.bdstatic.com/linksubmit/push.js":"http://push.zhanzhang.baidu.com/push.js";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(t,s)}()</script><script src="/js/local-search.js"></script><script>NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//cdnjs.cloudflare.com/ajax/libs/valine/1.3.10/Valine.min.js', () => {
    <!--var GUEST = ['nick', 'mail', 'link'];-->
    var GUEST = ['nick', 'mail'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el: '#valine-comments',
      verify: false,
      notify: false,
      appId: 'OuyHeA0XGL8hK4vgbqL0iERx-gzGzoHsz',
      appKey: 'L58VglKmWULcGK2W2AN7kWzM',
      placeholder: "留下邮箱，有回复时你将收到提醒，邮箱不会被公开。",
      avatar: 'wavatar',
      meta: guest,
      pageSize: '10' || 10,
      visitor: true,
      lang: 'zh-cn' || 'zh-cn',
      path: location.pathname,
      recordIP: true,
      serverURLs: ''
    });
  }, window.Valine);
});</script><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({pluginRootPath:"live2dw/",pluginJsPath:"lib/",pluginModelPath:"assets/",tagMode:!1,model:{jsonPath:"/live2dw/assets/wanko.model.json"},display:{position:"right",width:150,height:300},mobile:{show:!1},log:!1})</script></body><script type="text/javascript" src="/js/src/activetitle.js"></script></html><!-- rebuild by neat -->